home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / fidofilr.arc / FILER.C < prev    next >
Text File  |  1984-12-23  |  5KB  |  166 lines

  1. /*  Finds all SYSTEMxx.BBS files and prints the "directory" list of each
  2.     file area, a la Fido.  The file areas that are displayed are those
  3.     that callers with "normal" or lower privilege can enter.
  4.  
  5.     Note:  if you interrupt this program via control-C/control-Break,
  6.     you will be left in the subdirectory which was last being processed.
  7.     I would suggest issuing a "prompt" command like the following:
  8.  
  9.     prompt $d $t$_$p:
  10.  
  11.     DOS will then give you a two-line prompt consisting of current date
  12.     and time and the current path.
  13.  
  14.     This program was compiled using CI-C86 v2.10E.
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <bbs.h>
  19.  
  20. #define MAXLINE 128
  21.  
  22. extern    char    *fgets(),
  23.         *calloc(),
  24.         *gcdir(),
  25.         *filedir();
  26. extern    FILE    *fopen();
  27. extern    long    fseek();
  28.  
  29. /* */
  30.  
  31. /*    files():    Reads DIR.BBS and FILES.BBS
  32.             Displays to stdout the directory list a la Fido
  33.  
  34. */
  35.  
  36.         files()
  37.  
  38. {
  39.  
  40.     FILE    *bbs, *junk;
  41.     char    *buf, *ch;
  42.     long    fz;
  43.  
  44. if((buf=calloc(1,MAXLINE))==NULL)    /* get buffer space */
  45.   abort("FILER:  calloc buf fail");
  46.  
  47. if((junk=fopen("dir.bbs","r"))==NULL)   /* get heading info from DIR.BBS */
  48.   printf("no DIR.BBS\n");
  49.   else {
  50.     while(fgets(buf,MAXLINE,junk)!=NULL)
  51.       printf("%s",buf);
  52.     fclose(junk);
  53.     }
  54.  
  55. printf("\n");
  56.  
  57. if((bbs=fopen("files.bbs","r"))==NULL) {/* get filenames from FILES.BBS */
  58.   printf("No files\n");                 /* tell us about the missing file */
  59.   free(buf);                /* release buffer space */
  60.   return;                /* back to caller */
  61.   }
  62.  
  63. while(fgets(buf,MAXLINE,bbs)!=NULL) {    /* read each line in FILES.BBS */
  64.  
  65.   ch = buf;                /* set ch to begin of buffer */
  66.   if(*ch=='@') {                        /* '@' indicates beginning of uploads */
  67.     free(buf);                /* release buffer space */
  68.     return;                /* back to caller */
  69.     }
  70.   if((*ch==' ')||(*ch=='-')||
  71.      (*ch=='\n')) {                     /* if comment or empty line */
  72.     printf("%s",buf);                   /* just print it out and go */
  73.     continue;
  74.     }
  75.   while(!isspace(*ch++));        /* move ch to end of filename, buf points to filename */
  76.   *--ch = EOS;                /* terminate the filename portion for fopen() */
  77.   ch++;
  78.   if((junk=fopen(buf,"rb"))==NULL) {    /* does file exist?? */
  79.     printf("%-12s MISSING %s",buf,ch);  /* show us it's missing */
  80.     if(*ch==EOS) printf("\n");          /* no comment means we need a newline */
  81.     continue;                /* work on next line in FILES.BBS */
  82.     }
  83.   if((fz=fseek(junk,-1L,2))==-1L)    /* exists, get size-1 by fseek() to end of file */
  84.     abort("FILER:  err in fseek on %s",buf);
  85.   fclose(junk);             /* release the file */
  86.   printf("%-12s %7ld %s",buf,++fz,ch);  /* show us its size */
  87.   if(*ch==EOS) printf("\n");            /* no comment means we need a newline */
  88.  
  89.   } /* end of while(fgets... */
  90.  
  91. free(buf);                /* release buffer space */
  92. return;                 /* back to caller */
  93.  
  94. }   /* end of files() */
  95.  
  96. /* */
  97.  
  98.         main()
  99.  
  100. {
  101.  
  102. static    char    descr[40]="Download Area ";
  103.  
  104.     VSYS    vbbs;
  105.     FILE    *sysv;
  106.     int    working=TRUE, dirc=0, i;
  107.     char    *homedir, *curdir,
  108.         *tsys, *d,
  109.         sysname[16];
  110.  
  111. #define dpriv    vbbs._spriv
  112. #define dpath    vbbs._sfilepath
  113.  
  114. homedir = gcdir("");                    /* remember whence we came */
  115.  
  116. tsys=filedir("system*.bbs",0);          /* find all SYSTEMxx.BBS tables */
  117. if(!*tsys) {
  118.   free(tsys);
  119.   abort("FILER:  not in Fido's home directory!");
  120.   }
  121.  
  122. d = tsys;                /* note begin of filenames */
  123. while(TRUE) {                /* how many did we find? */
  124.   if(!*d) {                /* end of filename? */
  125.     d++;                /* yes, note start of next filename */
  126.     dirc++;                /* and count the name */
  127.     }
  128.   if(!*d)                /* end of all names? */
  129.     break;                /* yes, exit */
  130.   d++;                    /* go to next character */
  131.   }
  132. dirc--;                 /* accounts for "master" table */
  133. free(tsys);                /* don't need filenames now */
  134.  
  135. /*  for each SYSTEMxx.BBS found, if "normal" users are permitted to view the
  136.     directory, then move into the indicated subdirectory and read and display
  137.     the FILES.BBS a la Fido.
  138. */
  139.  
  140. for(i=1; i<=dirc; i++) {
  141.  
  142.   sprintf(sysname,"system%d.bbs",i);    /* construct filename */
  143.   if((sysv=fopen(sysname,"rb"))==NULL)  /* does table file exist? */
  144.     abort("FILER:  can't open %s",sysname);
  145.   if(fread(&vbbs,sizeof(VSYS),1,sysv)!=1)
  146.     abort("FILER:  error reading %s",sysname);
  147.   fclose(sysv);             /* don't need file any longer */
  148.   if((dpriv>NORMAL)||(dpath[0]==EOS)) { /* skip it if normal users can't get here */
  149.     chdir(homedir);            /* or if there is not an associated file area */
  150.     continue;
  151.     }
  152.   dpath[strlen(dpath)-1] = EOS;     /* kill last character of pathname */
  153.   if(chdir(dpath)!=0)            /* try to get to subdirectory */
  154.     abort("FILER:  can't chdir(%s)",dpath);
  155.   printf("Download Area #%d\n",i);      /* display some description */
  156.   files();                /* display FILES.BBS */
  157.   chdir(homedir);            /* back to home directory */
  158.  
  159.   }
  160.  
  161. exit(0);                /* back to DOS */
  162.  
  163. }   /* end of main() */
  164.  
  165. /* end of filer.c */
  166.